package net.halflite.mzkr.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.halflite.mzkr.type.TempUserType;
import net.halflite.mzkr.util.EncodeUtils;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * TempUserエンティティクラス
 * 
 */
@Entity
public class TempUser implements Serializable {

    private static final long serialVersionUID = 1L;

    /** idプロパティ */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public long id;

    /** registedUserIdプロパティ */
    public long registedUserId;

    /** hashプロパティ */
    public String hash;

    /** addressプロパティ */
    public String address;

    /** typeプロパティ */
    @Enumerated(EnumType.STRING)
    public TempUserType type;

    /** createdプロパティ */
    @Column(updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date created;

    /** modifiedプロパティ */
    @Temporal(TemporalType.TIMESTAMP)
    public Date modified;

    /** registedUser関連プロパティ */
    @ManyToOne
    @JoinColumn(name = "registed_user_id", referencedColumnName = "id")
    public RegistedUser registedUser;

    public TempUser(long registedUserId, String address, TempUserType type) {
		this.registedUserId = registedUserId;
		this.hash = EncodeUtils.md5(address);
		this.address = address;
		this.type = type;
		created = new Date();
		modified = new Date();
	}
    
    public TempUser() {
	}
    
	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}
}